package hasGroupsSizeX;

import java.util.Arrays;

public class Solution {
    public boolean hasGroupsSizeX(int[] deck) {
        Arrays.sort(deck);//排序
        int group=1;
        while(group<=deck.length){
            if(deck.length%group==0){
                //判断每个组是否相同
                //因为是有序的数组，所以只需要比较第一个和最后一个元素是否相同即可
                int x=deck.length/group;
                boolean isSame=true;
                for (int i = 0; i < deck.length; i+=x) {
                    if(deck[i]!=deck[i+x-1]){
                        isSame=false;
                        break;
                    }
                }
                if(isSame){
                    break;
                }
            }
            group++;
        }
        return deck.length/group>=2;
    }
}
